<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计数器案例</title>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        #app {
            width: 200px;
            height: 200px;
            margin: 200px auto;
        }

        #app button {
            width: 50px;
            height: 50px;
            background: darkgray;
            color: red;
            float: left;
        }

        #app span {
            background: rgb(250, 250, 250);
            width: 50px;
            height: 50px;
            display: block;
            float: left;
            line-height: 50px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <button @click="sub">-</button>
        <span> {{num}} </span>
        <button @click="add">+</button>
    </div>
    <script>
        // 创建vue 实例
        var app = new Vue({
            el: '#app',
            data: {
                num: 1
            },
            // 添加事件方法
            methods: {
                add: function () {
                    // console.log(111);
                    if (this.num < 10) {
                        this.num++;
                    } else {
                        alert('别点啦，最大啦！！！！')
                    }
                },
                sub: function () {
                    // console.log(222);
                    if (this.num > 0) {
                        this.num--;
                    } else {
                        alert('别点啦，最小啦！！！！')
                    }
                },
            }
        });
    </script>
</body>

</html>